﻿using System;
using System.Configuration;
using System.Net;
using System.Net.Mail;

namespace Ingebet.Utils
{
    public class EmailHelper
    {
        public static string Username
        {
            get
            {
                return ConfigurationManager.AppSettings["SmtpUtilisateur"];
            }
        }

        public static string Password
        {
            get
            {
                return ConfigurationManager.AppSettings["SmtpPassword"];
            }
        }

        public static string ServeurSmtp
        {
            get
            {
                return ConfigurationManager.AppSettings["SmtpServeur"];
            }
        }

        public static void SendEmail(string destinataire, string objet, string contenu)
        {
            MailMessage msg = new System.Net.Mail.MailMessage();

            msg.From = new MailAddress(Username);
            msg.Subject = objet;
            msg.To.Add(new MailAddress(destinataire));
            msg.Body = contenu;
            msg.IsBodyHtml = true;

            SmtpClient client = new SmtpClient(ServeurSmtp, 587);
            client.EnableSsl = true;
            client.Credentials = new System.Net.NetworkCredential(Username, Password);

            try
            {
                client.Send(msg);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}